from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import random
import datetime

random.seed(datetime.datetime.now())
def get_links(url):
    html = urlopen("https://baike.baidu.com" + url)
    bsObj = BeautifulSoup(html, "html.parser")

    return bsObj.find("dl", {"id": "posterCon"}).findAll("a", href=re.compile("^(/item/).*\/[0-9]*"))
links = get_links("/item/%E5%91%A8%E6%9D%B0%E4%BC%A6/129156")

while len(links) > 0:
    link = links[random.randint(0, len(links)-1)].attrs['href']
    print(link)
    links = get_links(link)
